
import java.util.Collection;
import java.util.List;

import javax.naming.Context;
import javax.naming.InitialContext;

import domain.model.Bank;
import domain.model.Customer;

import tp.ejb.test.TestFacadeRemote;

public class ClientTestFacade1 {

	public static void main(final String[] args) throws Exception {

		System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
				"org.jnp.interfaces.NamingContextFactory");
		System.setProperty(Context.PROVIDER_URL, "localhost:1099");
		System.setProperty(Context.URL_PKG_PREFIXES,
				"org.jboss.naming:org.jnp.interfaces");

		System.out.println("lookup TestFacade/remote ");

		TestFacadeRemote facadeBean = (TestFacadeRemote) new InitialContext()
				.lookup("TestFacade/remote");

		List<Bank> banks = facadeBean.getBanks();
		if (banks != null) {
			for (Bank bank : banks) {
				Collection<Customer> customers = bank.getCustomers();
				if (customers.size() > 0) {
					System.out.println("Liste des clients pour la banque "
							+ bank.getName() + " :");
						for (Customer customer : customers)
							System.out.println("    client: " + customer);
				} else
					System.out.println("la banque " + bank.getName()
							+ " n'a aucun client!!");
			}
		} else {
			System.out.println("Aucune banque");
		}

	}

}
